Code
using Pluto
using Random;
using Distributions;
using Plots;
using AverageShiftedHistograms;using Pluto
using Random;
using Distributions;
using Plots;
using AverageShiftedHistograms;function get_normals(samples::Vector{Float64})
means = zeros(0)
vars = zeros(0)
for i in 1:length(samples)
append!(means, mean(samples[1:i]))
if (i > 1)
append!(vars, var(samples[1:i]))
end
end
return means, vars
endfunction central_limit_theorem(N::Integer, d::Any)
x = rand(d, N)
μ, σ = get_normals(x)
return x, μ, σ
endn = 1000
M = 5dist = Logistic()
x, μ, σ = central_limit_theorem(n, dist);
anim = @animate for i = 1:10:n
plot(x[1:i], pdf(dist, x[1:i]), seriestype = :scatter, xlabel="Random Samples", title=("Samples: $(dist) Distribution \nn="*string(i)), lab=nothing)
end
display(gif(anim));dist = Logistic()
x, μ, σ = central_limit_theorem(n, dist);
anim = @animate for i = 1:10:n
o = ash(μ[1:i]; rng = -4:.1:4, m=M)
plot(o, xlabel="Mean Of The Random Samples", title=("Mean Of Samples Plotted When\nn="*string(i)), lab=nothing)
end
display(gif(anim));dist = Cosine()
x, μ, σ = central_limit_theorem(n, dist);
anim = @animate for i = 1:10:n
plot(x[1:i], pdf(dist, x[1:i]), seriestype = :scatter, xlabel="Random Samples", title=("Samples: $(dist) Distribution \nn="*string(i)), lab=nothing)
end
display(gif(anim));dist = Cosine()
x, μ, σ = central_limit_theorem(n, dist);
anim = @animate for i = 1:10:n
o = ash(μ[1:i]; rng = -4:.1:4, m=M)
plot(o, xlabel="Mean Of The Random Samples", title=("Mean Of Samples Plotted When\nn="*string(i)), lab=nothing)
end
display(gif(anim));dist = Uniform()
x, μ, σ = central_limit_theorem(n, dist);
anim = @animate for i = 1:10:n
plot(x[1:i], pdf(dist, x[1:i]), seriestype = :scatter, xlabel="Random Samples", title=("Samples: $(dist) Distribution \nn="*string(i)), lab=nothing)
end
display(gif(anim));dist = Uniform()
x, μ, σ = central_limit_theorem(n, dist);
anim = @animate for i = 1:10:n
o = ash(μ[1:i]; rng = -4:.1:4, m=M)
plot(o, xlabel="Mean Of The Random Samples", title=("Mean Of Samples Plotted When\nn="*string(i)), lab=nothing)
end
display(gif(anim));dist = Exponential()
x, μ, σ = central_limit_theorem(n, dist);
anim = @animate for i = 1:10:n
plot(x[1:i], pdf(dist, x[1:i]), seriestype = :scatter, xlabel="Random Samples", title=("Samples: $(dist) Distribution \nn="*string(i)), lab=nothing)
end
display(gif(anim));dist = Exponential()
x, μ, σ = central_limit_theorem(n, dist);
anim = @animate for i = 1:10:n
o = ash(μ[1:i]; rng = -4:.1:4, m=M)
plot(o, xlabel="Mean Of The Random Samples", title=("Mean Of Samples Plotted When\nn="*string(i)), lab=nothing)
end
display(gif(anim));dist = Arcsine()
x, μ, σ = central_limit_theorem(n, dist);
anim = @animate for i = 1:10:n
plot(x[1:i], pdf(dist, x[1:i]), seriestype = :scatter, xlabel="Random Samples", title=("Samples: $(dist) Distribution \nn="*string(i)), lab=nothing)
end
display(gif(anim));dist = Arcsine()
x, μ, σ = central_limit_theorem(n, dist);
anim = @animate for i = 1:10:n
o = ash(μ[1:i]; rng = -4:.1:4, m=M)
plot(o, xlabel="Mean Of The Random Samples", title=("Mean Of Samples Plotted When\nn="*string(i)), lab=nothing)
end
display(gif(anim));dist = Beta()
x, μ, σ = central_limit_theorem(n, dist);
anim = @animate for i = 1:10:n
plot(x[1:i], pdf(dist, x[1:i]), seriestype = :scatter, xlabel="Random Samples", title=("Samples: $(dist) Distribution \nn="*string(i)), lab=nothing)
end
display(gif(anim));dist = Beta()
x, μ, σ = central_limit_theorem(n, dist);
anim = @animate for i = 1:10:n
o = ash(μ[1:i]; rng = -4:.1:4, m=M)
plot(o, xlabel="Mean Of The Random Samples", title=("Mean Of Samples Plotted When\nn="*string(i)), lab=nothing)
end
display(gif(anim));